/*
 * Created on Jul 30, 2004
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package com.ba360.portal.util;

import java.io.StringReader;

import java.util.Random;



/**
 * @author ROnat
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Formatter {

	public static String formatString(String message)
	{
		return message.replaceAll("'","\\\\'");
	}
	
	public static void main(String args[])
	{
		String a ="The traitor tried to destroy America during his pitfull 4 years of disaster in the office. He should apologize and retire to CAR (Central Africa Republic) where he and other \"w\"arlord despots belong.";
		//System.out.println(a.replaceAll("'","\\\\'"));
		//System.out.println(Formatter.addNewLine(a,75));
		//System.out.println(Formatter.generateRandomPassword());
	}
	
	public static String generateRandomPassword()
	{
		String alphabet = "abcdefghijklmnopqrstuvwxyz";
	
		    Random random = new Random();
		    Integer appender = new Integer(random.nextInt());
		    String gwp = alphabet.charAt(Integer.parseInt(appender.toString().substring(1,2)))+appender.toString().substring(1,2)+appender.toString().substring(1,5);
		    return gwp;
	}
	
	public static String addNewLine(String text,int cols)
	{
		if (text.length()<cols)
		{
			return text;
		}
		StringReader sr = new StringReader(text);
		StringBuffer sbf = new StringBuffer(text);
		int mod = text.length()/cols;
		for (int i=0;i<mod;i++)
		{
			sbf.insert((i+1)*cols+i*3,"<br>");
		}
		System.out.println(mod);
	//	System.out.println(sbf.toString());
		//StringWriter sw  = new StringWriter()
		return sbf.toString();
	}
}
